% parameters
% Constant timestepping: grid S doubled for each run, timestep doubled.

rows = 5; % how many time you want to run the program
T = 0.25; step0 = 25;
sigma = 0.4; r = 0.03; S0 = 100; K = 100;
option = 0; method = 0:2;

% Values
nodeM = 1:rows;
% Time Step
steps = step0*2.^(0:rows-1);
V = zeros(rows,1);
nNode = zeros(rows,1);

tic
% Fully Implicit
for i=1:rows
    [V(i), p1, optionV] = EUImplicit(r,sigma,S0,K,T,steps(i),method(1),option,nodeM(i));
    nNode(i) = length(optionV);
end
change = [0;diff(V)];
ratio = [0;0;change(2:end-1)./change(3:end)];
OutputFI = [nNode,steps',V,change,ratio];
figure
% Crank Nicolson
for i=1:rows
    [V(i), p1, optionV] = EUImplicit(r,sigma,S0,K,T,steps(i),method(2),option,nodeM(i));
    nNode(i) = length(optionV);
end
% C-N R
change = [0;diff(V)];
ratio = [0;0;change(2:end-1)./change(3:end)];
OutputCN = [nNode,steps',V,change,ratio];
figure
for i=1:rows
    [V(i), p1, optionV] = EUImplicit(r,sigma,S0,K,T,steps(i),method(3),option,nodeM(i));
    nNode(i) = length(optionV);
end
toc
change = [0;diff(V)];
ratio = [0;0;change(2:end-1)./change(3:end)];
OutputCNR = [nNode,steps',V,change,ratio];



